package controllers

import (
	"fmt"
	"goconfcenter/core/consts"
	"goconfcenter/core/enums"
	"goconfcenter/core/response"
	"goconfcenter/pkg/Util"
	"goconfcenter/settings"

	"github.com/gin-gonic/gin"
)

type CommonController struct {
}

// Conf 初始化加载引用基本配置
func (c *CommonController) Conf(context *gin.Context) {
	conf := map[string]interface{}{
		"enums":  getEnums(),
		"crypto": getCryTo(),
	}
	response.Success(context, consts.CurdStatusOkMsg, conf)
}
func getEnums() map[string]interface{} {
	enumsList := map[string]interface{}{
		"resourceType":        enums.GetResourceTypeList(),
		"backendUserAuthType": enums.GetAuthTypeList(),
		"yesOrNo":             enums.GetYesOrNoList(),
		"enableOrNo":          enums.GetEnableOrNotList(),
	}
	return enumsList
}

// getCryTo 前端使用后端获取的公钥
func getCryTo() map[string]interface{} {
	//rsaKey,_:=Util.GenerateRsaKeyBase64()
	publicKey := settings.Conf.AppConfig.MyPublicKey
	privateKey := settings.Conf.AppConfig.MyPrivateKey
	pubKeySign, _ := Util.RsaSignBase64([]byte(publicKey), privateKey)
	boolSign := Util.RsaVerifySignBase64([]byte(publicKey), pubKeySign, publicKey)
	fmt.Println(boolSign)
	crypto := map[string]interface{}{
		"pubKey":     publicKey,
		"pubKeySign": pubKeySign,
	}
	return crypto
}
